<!DOCTYPE html>
<html lang="en">

<head>
    <title></title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="css/style.css" rel="stylesheet">
</head>

<body>
    <script>
        let graph = [[1, 2, 3], [3], [3], [4], []]
        var allPathsSourceTarget = function (graph) {
            debugger
            const len = graph.length
            const res = []
            const dps = (n, arr) => {
                // 如果走到终点了，就是一条完整的线路
                if (n === len - 1) {
                    return res.push(arr)
                }
                // 如果没有下一个节点了，退出
                const list = graph[n]
                if (!list.length) return
                for (const l of list) {
                    // 先寻找一条路线
                    arr.push(l)
                    dps(l, arr.slice())
                    // 再退回来走另外一条路线
                    arr.pop()
                }
            }
            dps(0, [0])
            console.log(res.length)
            return res.length;
        };
        allPathsSourceTarget(graph);

    </script>
</body>

</html>